YAHOO.example.autocomplete = function() {
        var oConfigs = {
            prehighlightClassName: "yui-ac-prehighlight",
            queryDelay: .5,
            minQueryLength: 3,
            animVert: .01,
        }
        
        // instantiate remote data source
        // code based on example at 
        // http://developer.yahoo.com/yui/examples/autocomplete/ac_basic_xhr.html
        var oDSEmpresa = new YAHOO.util.DataSource("/empresa/index"); 
        oDSEmpresa.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; 
        oDSEmpresa.responseSchema = { fields: ['razao_social',	'id']             
        }; 
        oDSEmpresa.maxCacheEntries = 10;         
      
        // instantiate YUI autocomplete widgets
        var oAC0 = new YAHOO.widget.AutoComplete("empresa", "empresa_container", oDSEmpresa, oConfigs);
        oAC0.generateRequest = function(sQuery) {
        	return "?razao_social=" + sQuery; 
		};
		oAC0.autoHighlight = true;
		var myHiddenField = YAHOO.util.Dom.get("empresa_id");
		//alert(MyHiddenField.value);
		var myHandler = function(sType, aArgs) {
	        var myAC = aArgs[0]; // reference back to the AC instance
	        var elLI = aArgs[1]; // reference to the selected LI element
	        var oData = aArgs[2]; // object literal of selected item's result data
	        
	        // update hidden form field with the selected item's ID
	        //$("empresa").value = oData.id;
	        myHiddenField.value = oData[1];
	        //alert(myHiddenField.value);
	    };
	    oAC0.itemSelectEvent.subscribe(myHandler);
        return {
            oDSEmpresa: oDSEmpresa,
            oAC0: oAC0
            };
      }();
	
function ValidateForm(e){
	var element = Event.element(e);
	if (element.value.length>0){
		var dt=element.getValue();
		if (isDate(dt)==false){
			element.value = '';
			return false;
		}else{
	    return true}
	}
 }

function validaEmpresa(e){
	var emp = $("empresa").getValue();
	var aux = $("empresa_id");
	if   (emp.length==0){aux.value = '';}
	else{}
}

$("form_dtnascimento").observe("blur",ValidateForm)
$("empresa").observe("blur",validaEmpresa)